﻿////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, //
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 		        //
// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.		    //
// 																				                                                //
//							                        Copyright (c) UIROBOT. 								            //
// 							                            All rights reserved.								                //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "LoadSimCanFunc.h"

// SETQUICKSCAN    SetQuickScan;
GETLASTERR      GetLastErr;
SEARCHGATEWAY   SearchGateway;
OPENGATEWAY     OpenGateway;
CLOSEGATEWAY    CloseGateway;
GETMDL          GetMDL;
SETCFG          SetCFG;
GETCFG          GetCFG;
SETSPD          SetSPD;
GETSPD          GetSPD;
SETSTP          SetSTP;
GETSTP          GetSTP;
SETQEC          SetQEC;
GETQEC          GetQEC;
SETPOS          SetPOS;
GETPOS          GetPOS;
UIMREGRTCNCALLBACK UIMRegRtcnCallBack;
SETORG          SetORG;
UIMENA          UimENA;
UIMOFF          UimOFF;
//UIMACK          UimAck;
//typedef void (*SETQUICKSCAN)(int nComPort, int nBandRate,int nGatewayID);
//typedef void (*SET242QUICKSCAN)(int nComPort, int nBandRate,int nGatewayID);

//    SETDEVINDEX     SetDevIndex;
//    GETUIMDEVIDLIST GetUimDevIdList;
//    SEARCHDEVICE    SearchDevice;
//    GETUIMDEVINFO   GetUimDevInfo;
//    OPENUIMDEV      OpenUimDev;
//    CLOSEUIMDEV     CloseUimDev;
//    UIMGROBREG      UimGrobReg;
//    UIMFBK          UimFbk;
//    UIMSFBK         UimSfbk;
//    SETGOFF         SetgOFF;
//    SETGCUR         SetgCUR;
//    SETGORG         SetgORG;
//    SETGDIR         SetgDIR;
//    SETGSPD         SetgSPD;
//    SETGSTP         SetgSTP;
//    SETGPOS         SetgPOS;
//    SETGQEC         SetgQEC;
//    GETUIMMCFG      GetUimMCFG;
//    SETUIMMCFG      SetUimMCFG;
//    SETMACC         SetmACC;
//    GETMACC         GetmACC;
//    SETMDEC         SetmDEC;
//    GETMDEC         GetmDEC;
//    SETMMDS         SetmMDS;
//    GETMMDS         GetmMDS;
//    SETMMSS         SetmMSS;
//    GETMMSS         GetmMSS;
//    GETSTG          GetSTG;
//    SETSTG          SetSTG;
//    SETQER          SetQER;
//    SETSQT          SetSQT;
//    GETSQT          GetSQT;
//    SETBDR          SetBDR;
//    SETADR          SetADR;
//    SETGMCS         SetgMCS;
//    SETGDOUT        SetgDOUT;
//    SETGACR         SetgACR;
//    UIMSTORE        UimStore;
//    SETACR          SetACR;
//    GETACR          GetACR;
//    SETMCS          SetMCS;
//    GETMCS          GetMCS;
//    SETCUR          SetCUR;
//    GETCUR          GetCUR;
//    SETRPT          SetRPT;
//    GETRPT          GetRPT;
//    SETRPC          SetRPC;
//    GETRPC          GetRPC;
//    SETATCONH       SetATCONH;
//    GETATCONH       GetATCONH;
//    SETATCONL       SetATCONL;
//    GETATCONL       GetATCONL;
//    SETBTR          SetBTR;
//    GETBTR          GetBTR;
//    GETSCFG         GetSCFG;
//    SETS12CON       SetS12CON;
//    GETS12CON       GetS12CON;
//    SETS34CON       SetS34CON;
//    GETS34CON       GetS34CON;
//    SETDOUT         SetDOUT;
//    GETDOUT         GetDOUT;
//    SETUIDMCFG      SetUIDMCFG;
//    GETUIDMCFG      GetUIDMCFG;
//    SETIOCONFIG     SetIOconfig;
//    GETIOCONFIG     GetIOconfig;
//    SETDVAINFO      SetDVAInfo;
//    GETDVAINFO      GetDVAInfo;
//    GETAVAINFO      GetAVAInfo;
//    SETPMB          SetPMB;
//    GETPMB          GetPMB;
//    SETPMD          SetPMD;
//    GETPMD          GetPMD;
//    SETPBR          SetPBR;
//    GETPBR          GetPBR;
//    SETDMA          SetDMA;
//    GETDMA          GetDMA;
//    SETOPR          SetOPR;
//    OPRREAD         OPRRead;
//    OPRREADPTR      OPRReadPtr;

//    GETUIMICFG      GetUimICFG;
//    SETUIMICFG      SetUimICFG;
//    UIMADVENA       UimAdvENA;
//    UIMGETADVENA    UimGetAdvENA;
//    UIMADVSTORE     UimAdvStore;
//    GETBLC          GetBLC;
//    SETBLC          SetBLC;
//    GETQER          GetQER;
//    SETNRD          SetNRD;
//    OPR_OPENANTENNA OPR_OpenAntenna;
//    OPR_CLOSEANTENNA OPR_CloseAntenna;
//    OPR_FINDRFID    OPR_FindRFID;
//    OPR_CLOSERFID   OPR_CloseRFID;
//    OPR_RFIDREAD    OPR_RFIDRead;
//    OPR_RFIDWRITE   OPR_RFIDWrite;
//    OPR_SETRFIDKEY  OPR_SetRFIDKey;
//    OPR_GETRFIDBLKDATA OPR_GetRFIDBlkData;
//    OPR_SETRFIDBLKDATA OPR_SetRFIDBlkData;
//    OPR_GETRFIDCARDNUM OPR_GetRFIDCardNum;

//    FORCESTOPPROGRAM ForceStopProgram;

//    GETLASTERR      GetSDKLastErr;

QLibrary *uimDll = nullptr;

int LoadSimCanFunc(const QString dllName)
{
    // SetQuickScan = nullptr;
    GetLastErr = nullptr;
    SearchGateway = nullptr;
    OpenGateway = nullptr;
    CloseGateway = nullptr;

    GetMDL = nullptr;
    SetCFG = nullptr;
    GetCFG = nullptr;
    SetSPD = nullptr;
    GetSPD = nullptr;
    SetSTP = nullptr;
    GetSTP = nullptr;
    SetQEC = nullptr;
    GetQEC = nullptr;
    SetPOS = nullptr;
    GetPOS = nullptr;
    UIMRegRtcnCallBack = nullptr;
    SetORG = nullptr;
    UimENA = nullptr;
    UimOFF = nullptr;

    uimDll = new QLibrary();
    uimDll->setFileName(dllName);

    if(!uimDll->load()){
        return -1;
    }

    GetLastErr = (GETLASTERR)uimDll->resolve("GetLastErr");
    //打开和关闭网关替代函数
    // SetQuickScan = (SETQUICKSCAN)uimDll->resolve("SetQuickScan");
    SearchGateway = (SEARCHGATEWAY)uimDll->resolve("SearchGateway");
    OpenGateway = (OPENGATEWAY)uimDll->resolve("OpenGateway");
    CloseGateway = (CLOSEGATEWAY)uimDll->resolve("CloseGateway");
    //
    GetMDL = (GETMDL)uimDll->resolve("GetMDL");
    //寄存器设置替代函数
    SetCFG = (SETCFG)uimDll->resolve("SetCFG");
    GetCFG = (GETCFG)uimDll->resolve("GetCFG");
    //
    SetSPD = (SETSPD)uimDll->resolve("SetSPD");
    GetSPD = (GETSPD)uimDll->resolve("GetSPD");
    SetSTP = (SETSTP)uimDll->resolve("SetSTP");
    GetSTP = (GETSTP)uimDll->resolve("GetSTP");
    SetQEC = (SETQEC)uimDll->resolve("SetQEC");
    GetQEC = (GETQEC)uimDll->resolve("GetQEC");
    SetPOS = (SETPOS)uimDll->resolve("SetPOS");
    GetPOS = (GETPOS)uimDll->resolve("GetPOS");
    //
    UIMRegRtcnCallBack = (UIMREGRTCNCALLBACK)uimDll->resolve("UIMRegRtcnCallBack");
    SetORG = (SETORG)uimDll->resolve("SetORG");
    UimENA = (UIMENA)uimDll->resolve("UimENA");
    UimOFF = (UIMOFF)uimDll->resolve("UimOFF");
//    UimAck = (UIMACK)uimDll->resolve("UimAck");
    //
//    SetMCS = (SETMCS)uimDll->resolve("SetMCS");
//    GetMCS = (GETMCS)uimDll->resolve("GetMCS");
//    SetCUR = (SETCUR)uimDll->resolve("SetCUR");
//    GetCUR = (GETCUR)uimDll->resolve("GetCUR");

//    SetDevIndex = (SETDEVINDEX)uimDll->resolve("SetDevIndex");
//    GetUimDevIdList = (GETUIMDEVIDLIST)uimDll->resolve("GetUimDevIdList");
//    SearchDevice = (SEARCHDEVICE)uimDll->resolve("SearchDevice");
//    GetUimDevInfo = (GETUIMDEVINFO)uimDll->resolve("GetUimDevInfo");
//    OpenUimDev = (OPENUIMDEV)uimDll->resolve("OpenUimDev");
//    CloseUimDev = (CLOSEUIMDEV)uimDll->resolve("CloseUimDev");
//    UimGrobReg = (UIMGROBREG)uimDll->resolve("UimGrobReg");
//    UimFbk = (UIMFBK)uimDll->resolve("UimFbk");
//    UimSfbk = (UIMSFBK)uimDll->resolve("UimSfbk");
//    SetgOFF = (SETGOFF)uimDll->resolve("SetgOFF");
//    SetgCUR = (SETGCUR)uimDll->resolve("SetgCUR");
//    SetgORG = (SETGORG)uimDll->resolve("SetgORG");
//    SetgDIR = (SETGDIR)uimDll->resolve("SetgDIR");
//    SetgSPD = (SETGSPD)uimDll->resolve("SetgSPD");
//    SetgSTP = (SETGSTP)uimDll->resolve("SetgSTP");
//    SetgPOS = (SETGPOS)uimDll->resolve("SetgPOS");
//    SetgQEC = (SETGQEC)uimDll->resolve("SetgQEC");
//    GetUimMCFG = (GETUIMMCFG)uimDll->resolve("GetUimMCFG");
//    SetUimMCFG = (SETUIMMCFG)uimDll->resolve("SetUimMCFG");
//    SetmACC = (SETMACC)uimDll->resolve("SetmACC");
//    GetmACC = (GETMACC)uimDll->resolve("GetmACC");
//    SetmDEC = (SETMDEC)uimDll->resolve("SetmDEC");
//    GetmDEC = (GETMDEC)uimDll->resolve("GetmDEC");
//    SetmMDS = (SETMMDS)uimDll->resolve("SetmMDS");
//    GetmMDS = (GETMMDS)uimDll->resolve("GetmMDS");
//    SetmMSS = (SETMMSS)uimDll->resolve("SetmMSS");
//    GetmMSS = (GETMMSS)uimDll->resolve("GetmMSS");
//    GetSTG = (GETSTG)uimDll->resolve("GetSTG");
//    SetSTG = (SETSTG)uimDll->resolve("SetSTG");
//    SetQER = (SETQER)uimDll->resolve("SetQER");
//    SetSQT = (SETSQT)uimDll->resolve("SetSQT");
//    GetSQT = (GETSQT)uimDll->resolve("GetSQT");
//    SetBDR = (SETBDR)uimDll->resolve("SetBDR");
//    SetADR = (SETADR)uimDll->resolve("SetADR");
//    SetgMCS = (SETGMCS)uimDll->resolve("SetgMCS");
//    SetgDOUT = (SETGDOUT)uimDll->resolve("SetgDOUT");
//    SetgACR = (SETGACR)uimDll->resolve("SetgACR");
//    UimStore = (UIMSTORE)uimDll->resolve("UimStore");
//    SetACR = (SETACR)uimDll->resolve("SetACR");
//    GetACR = (GETACR)uimDll->resolve("GetACR");
//    SetRPT = (SETRPT)uimDll->resolve("SetRPT");
//    GetRPT = (GETRPT)uimDll->resolve("GetRPT");
//    SetRPC = (SETRPC)uimDll->resolve("SetRPC");
//    GetRPC = (GETRPC)uimDll->resolve("GetRPC");
//    SetATCONH = (SETATCONH)uimDll->resolve("SetATCONH");
//    GetATCONH = (GETATCONH)uimDll->resolve("GetATCONH");
//    SetATCONL = (SETATCONL)uimDll->resolve("SetATCONL");
//    GetATCONL = (GETATCONL)uimDll->resolve("GetATCONL");
//    SetBTR = (SETBTR)uimDll->resolve("SetBTR");
//    GetBTR = (GETBTR)uimDll->resolve("GetBTR");
//    GetSCFG = (GETSCFG)uimDll->resolve("GetSCFG");
//    SetS12CON = (SETS12CON)uimDll->resolve("SetS12CON");
//    GetS12CON = (GETS12CON)uimDll->resolve("GetS12CON");
//    SetS34CON = (SETS34CON)uimDll->resolve("SetS34CON");
//    GetS34CON = (GETS34CON)uimDll->resolve("GetS34CON");
//    SetDOUT = (SETDOUT)uimDll->resolve("SetDOUT");
//    GetDOUT = (GETDOUT)uimDll->resolve("GetDOUT");
//    SetUIDMCFG = (SETUIDMCFG)uimDll->resolve("SetUIDMCFG");
//    GetUIDMCFG = (GETUIDMCFG)uimDll->resolve("GetUIDMCFG");
//    SetIOconfig = (SETIOCONFIG)uimDll->resolve("SetIOconfig");
//    GetIOconfig = (GETIOCONFIG)uimDll->resolve("GetIOconfig");
//    SetDVAInfo = (SETDVAINFO)uimDll->resolve("SetDVAInfo");
//    GetDVAInfo = (GETDVAINFO)uimDll->resolve("GetDVAInfo");
//    GetAVAInfo = (GETAVAINFO)uimDll->resolve("GetAVAInfo");
//    SetPMB = (SETPMB)uimDll->resolve("SetPMB");
//    GetPMB = (GETPMB)uimDll->resolve("GetPMB");
//    SetPMD = (SETPMD)uimDll->resolve("SetPMD");
//    GetPMD = (GETPMD)uimDll->resolve("GetPMD");
//    SetPBR = (SETPBR)uimDll->resolve("SetPBR");
//    GetPBR = (GETPBR)uimDll->resolve("GetPBR");
//    SetDMA = (SETDMA)uimDll->resolve("SetDMA");
//    GetDMA = (GETDMA)uimDll->resolve("GetDMA");
//    SetOPR = (SETOPR)uimDll->resolve("SetOPR");
//    OPRRead = (OPRREAD)uimDll->resolve("OPRRead");
//    OPRReadPtr = (OPRREADPTR)uimDll->resolve("OPRReadPtr");
//    GetUimICFG = (GETUIMICFG)uimDll->resolve("GetUimICFG");
//    SetUimICFG = (SETUIMICFG)uimDll->resolve("SetUimICFG");
//    UimAdvENA = (UIMADVENA)uimDll->resolve("UimAdvENA");
//    UimGetAdvENA = (UIMGETADVENA)uimDll->resolve("UimGetAdvENA");
//    UimAdvStore = (UIMADVSTORE)uimDll->resolve("UimAdvStore");
//    GetBLC = (GETBLC)uimDll->resolve("GetBLC");
//    SetBLC = (SETBLC)uimDll->resolve("SetBLC");
//    GetQER = (GETQER)uimDll->resolve("GetQER");
//    SetNRD = (SETNRD)uimDll->resolve("SetNRD");
//    OPR_OpenAntenna = (OPR_OPENANTENNA)uimDll->resolve("OPR_OpenAntenna");
//    OPR_CloseAntenna = (OPR_CLOSEANTENNA)uimDll->resolve("OPR_CloseAntenna");
//    OPR_FindRFID = (OPR_FINDRFID)uimDll->resolve("OPR_FindRFID");
//    OPR_CloseRFID = (OPR_CLOSERFID)uimDll->resolve("OPR_CloseRFID");
//    OPR_RFIDRead = (OPR_RFIDREAD)uimDll->resolve("OPR_RFIDRead");
//    OPR_RFIDWrite = (OPR_RFIDWRITE)uimDll->resolve("OPR_RFIDWrite");
//    OPR_SetRFIDKey = (OPR_SETRFIDKEY)uimDll->resolve("OPR_SetRFIDKey");
//    OPR_GetRFIDBlkData = (OPR_GETRFIDBLKDATA)uimDll->resolve("OPR_GetRFIDBlkData");
//    OPR_SetRFIDBlkData = (OPR_SETRFIDBLKDATA)uimDll->resolve("OPR_SetRFIDBlkData");
//    OPR_GetRFIDCardNum = (OPR_GETRFIDCARDNUM)uimDll->resolve("OPR_GetRFIDCardNum");
//    ForceStopProgram = (FORCESTOPPROGRAM)uimDll->resolve("ForceStopProgram");
//    GetSDKLastErr = (GETLASTERR)uimDll->resolve("GetSDKLastErr");

    if(GetLastErr == nullptr
            || SearchGateway == nullptr
            || OpenGateway == nullptr
            || CloseGateway == nullptr
            || GetMDL == nullptr
            || SetCFG == nullptr
            || GetCFG == nullptr
            || SetSPD == nullptr
            || GetSPD == nullptr
            || SetSTP == nullptr
            || GetSTP == nullptr
            || SetQEC == nullptr
            || GetQEC == nullptr
            || SetPOS == nullptr
            || GetPOS == nullptr
            || UIMRegRtcnCallBack == nullptr
            || SetORG == nullptr
//            || UimAck == nullptr
//            || SetMCS == nullptr
//            || GetMCS == nullptr
//            || SetCUR == nullptr
//            || GetCUR == nullptr
//            || SetDevIndex == nullptr
//            || GetUimDevIdList == nullptr
//            || SearchDevice == nullptr
//            || GetUimDevInfo == nullptr
//            || OpenUimDev == nullptr
//            || CloseUimDev == nullptr
//            || UimGrobReg == nullptr
//            || UimEna == nullptr
//            || UimOff == nullptr
//            || UimFbk == nullptr
//            || UimSfbk == nullptr
//            || SetgOFF == nullptr
//            || SetgCUR == nullptr
//            || SetgORG == nullptr
//            || SetgDIR == nullptr
//            || SetgSPD == nullptr
//            || SetgSTP == nullptr
//            || SetgPOS == nullptr
//            || SetgQEC == nullptr
//            || GetUimMCFG == nullptr
//            || SetUimMCFG == nullptr
//            || SetmACC == nullptr
//            || GetmACC == nullptr
//            || SetmDEC == nullptr
//            || GetmDEC == nullptr
//            || SetmMDS == nullptr
//            || GetmMDS == nullptr
//            || SetmMSS == nullptr
//            || GetmMSS == nullptr
//            || GetSTG == nullptr
//            || SetSTG == nullptr
//            || SetQER == nullptr
//            || SetSQT == nullptr
//            || GetSQT == nullptr
//            || SetBDR == nullptr
//            || SetADR == nullptr
//            || SetgMCS == nullptr
//            || SetgDOUT == nullptr
//            || SetgACR == nullptr
//            || UimStore == nullptr
//            || SetACR == nullptr
//            || GetACR == nullptr
//            || SetRPT == nullptr
//            || GetRPT == nullptr
//            || SetRPC == nullptr
//            || GetRPC == nullptr
//            || SetATCONH == nullptr
//            || GetATCONH == nullptr
//            || SetATCONL == nullptr
//            || GetATCONL == nullptr
//            || SetBTR == nullptr
//            || GetBTR == nullptr
//            || GetSCFG == nullptr
//            || SetS12CON == nullptr
//            || GetS12CON == nullptr
//            || SetS34CON == nullptr
//            || GetS34CON == nullptr
//            || SetDOUT == nullptr
//            || GetDOUT == nullptr
//            || SetUIDMCFG == nullptr
//            || GetUIDMCFG == nullptr
//            || SetIOconfig == nullptr
//            || GetIOconfig == nullptr
//            || SetDVAInfo == nullptr
//            || GetDVAInfo == nullptr
//            || GetAVAInfo == nullptr
//            || SetPMB == nullptr
//            || GetPMB == nullptr
//            || SetPMD == nullptr
//            || GetPMD == nullptr
//            || SetPBR == nullptr
//            || GetPBR == nullptr
//            || SetDMA == nullptr
//            || GetDMA == nullptr
//            || SetOPR == nullptr
//            || OPRRead == nullptr
//            || OPRReadPtr == nullptr
//            || GetUimICFG == nullptr
//            || SetUimICFG == nullptr
//            || UimAdvENA == nullptr
//            || UimGetAdvENA == nullptr
//            || UimAdvStore == nullptr
//            || GetBLC == nullptr
//            || SetBLC == nullptr
//            || GetQER == nullptr
//            || SetNRD == nullptr
//            || OPR_OpenAntenna == nullptr
//            || OPR_CloseAntenna == nullptr
//            || OPR_FindRFID == nullptr
//            || OPR_CloseRFID == nullptr
//            || OPR_RFIDRead == nullptr
//            || OPR_RFIDWrite == nullptr
//            || OPR_SetRFIDKey == nullptr
//            || OPR_GetRFIDBlkData == nullptr
//            || OPR_SetRFIDBlkData == nullptr
//            || OPR_GetRFIDCardNum == nullptr
//            || ForceStopProgram == nullptr
//            || GetSDKLastErr == nullptr
            )
    {
        return -2;
    }
    return 0;
}

void FreeSimCanFunc(void)
{
    if(uimDll == nullptr){
        return;
    }
    if(uimDll->isLoaded()){
        uimDll->unload();
    }
    delete uimDll;
    uimDll = nullptr;
}
